package com.jt.web.controller;

import com.fasterxml.jackson.databind.util.JSONPObject;
import com.jt.pojo.ItemDesc;
import com.jt.util.ObjectMapperUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class JSONPController {

    /**
     * 完成JSONP跨域访问
     */

    public String jsonp1(String callback){
        ItemDesc itemDesc = new ItemDesc();
        itemDesc.setItemId(101l).setItemDesc("跨域访问");
        String json = ObjectMapperUtil.toJSON(itemDesc);
        return callback+"("+json+")";
    }

    @RequestMapping("/web/testJSONP")
    public JSONPObject jsonp(String callback){
        ItemDesc itemDesc = new ItemDesc();
        itemDesc.setItemId(101l).setItemDesc("跨域访问");
        return new JSONPObject(callback, itemDesc);
    }

}
